<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" type="text/css" href="css/mainstyle.css" />
    <link rel="icon" href="image/logo.ico" type="image/x-icon">
    <title>疫苗预约</title>
    <style type="text/css">
        #state_date{
            font-size: 0.5rem;
        }

    </style>
    <?php 
        include_once 'api/DBcon.php';
        $result=false;
        $link=OpenDB();
        @session_start();
        $userid=$_SESSION['idUser'];//取账号

        $headImgSrc="image/15666876092.jpg";//默认头像路径
        $userName=$userid;

        if($link){
            $query="select * from user where iduser='${userid}';";//查询账号信息
            $result = mysqli_query($link,$query);
            if(mysqli_num_rows($result)) { //账号存在
                $row = mysqli_fetch_array($result);//读取结果
                if($row['imgsrc']!=null)
                    $headImgSrc=$row['imgsrc'];
                    
                if($row['USERNAME']!=null)
                    $userName=$row['USERNAME'];
            }
            else{
                echo "<script>alert('数据库出错！');</script>";
            }
            $query2="select * from information where userid='${userid}';";//查询账号内成员
            $result2 = mysqli_query($link,$query2);
            $familyNum=mysqli_num_rows($result2);//有无成员
            if($familyNum) { //存在
                $rows = mysqli_fetch_all($result2);//读取结果
            }
            else{//没有成员
                echo "<script>alert(\"还没有成员信息，点击右上角'+'添加成员！\");</script>";
            }
        }
        $_SESSION['imgsrc']=$headImgSrc;
        $_SESSION['userName']=$userName;//用户名头像存入session供其他页面取用
    ?>
</head>
<body>
    <div id="left_part">
    <div id="navigationBar">
        <div id=logo>
            <img src="image/logo1.png" title="疫苗预约" id="logoimg"/>
            <img src="image/text.png" title="yuyue" id="logotext"/>
        </div>
        <div id="buttons">
            
            <div class="button1" id="family">
                <img src="image/jiaren.png" title="我的家人" id="icon"/>
                我的家人
            </div>
            <a href="main_reservation.php">
            <div class="button" id="reservation" onmouseover="this.style.background='#84858d14'" onmouseout="this.style.background=''">
                <img src="image/yuyue.png" title="预约注射" id="icon"/>
                预约注射
            </div></a>
            <a href="main_notice.php">
            <div class="button" id="notice" onmouseover="this.style.background='#84858d14'" onmouseout="this.style.background=''">
                <img src="image/zhuyi.png" title="注意事项" id="icon"/>
                注意事项
            </div>
            </a>
        </div>   
    </div>
    <div id="user">
        <img src="<?php echo $headImgSrc;?>" title="我的" id="headimg"/>
        <div id="userId"><?php echo $userName;?></div>
        <a href="updateuser.php"><img src="image/dangan.png" title="修改信息" id="myId"/></a>
        
    </div>
    <a href="index.php"><div id="bottom">退出登录</div></a>
</div>
    <div id="main">
        <div id="main_head">
            <div id="main_head_text">我的家人></div>
            <a href="addfamily.php">
            <div id="main_head_imgb"><img src="image/增加.png" title="添加成员" id="main_head_icon"/></div></a>
        </div>
        <div id="main_body">
            <?php
            for($i=0;$i<$familyNum;$i++){
                $state="未预约";//状态信息
                $type='';//疫苗类型
                $printDate='';//页面显示的时间
                if($rows[$i][4]=="ready1"){
                    $state="已预约";                   
                    $date=explode('-',$rows[$i][7]);
                    $printDate=$date[1].'月'.$date[2].'日'.$rows[$i][8].'第一针';
                }
                if($rows[$i][4]=="ready2"){
                    $state="已预约";                   
                    $date=explode('-',$rows[$i][9]);
                    $printDate=$date[1].'月'.$date[2].'日'.$rows[$i][10].'第二针';
                }
                if($rows[$i][4]=="finish1"){
                    $state="已注射";                   
                    $printDate='  第一针';
                }
                if($rows[$i][4]=="finish2"){
                    $state="已注射";                   
                    $printDate='  第二针';
                }
                $id=substr($rows[$i][0],0,4)."**********".substr($rows[$i][0],14);
                echo "<div id=\"card1\">
                <h4 id=\"card_name\">".$rows[$i][1]."</h4>
                <div id=\"card_state\">
                    <img id=\"card_state_icon\" src=\"image/zhushe.png\"/>
                    ${state}<br/>
                    <div id=\"state_date\">${printDate}</div>
                </div>
                <img src=\"".$rows[$i][6]."\" title=\"信息二维码\" id=\"erweima\"/>
                <p id=\"card_sexage\">".$rows[$i][2]."&nbsp;&nbsp;&nbsp;&nbsp;".$rows[$i][3]."</p>
                <p id=\"card_id\">${id}</p>
                <p id=\"card_banquan\">文华学院信息学部监制</p>
            </div>";
            } 
            ?>
        </div>
        <div id="main_bottom">
            <span>地址：武汉市东湖新技术开发区文华园路8号</span>
            <span>作者：文华学院信息学部计科1806刘昊天</span>
        </div>
    </div>
    
</body>
</html>